

'--------------------------------------------------
' Hands-On 18-1
' Statements to be entered in the Immediate Window
'--------------------------------------------------

Application.Dialogs(xlDialogFont).Show
Application.Dialogs(xlDialogFontProperties).Show
Application.Dialogs(xlDialogDefineName).Show
Application.Dialogs(xlDialogOptionsView).Show
Application.Dialogs(xlDialogClear).Show 1
Application.Dialogs(xlDialogFont).Show "Arial", 14
Application.Dialogs(xlDialogFont).Show , 8
Application.Dialogs(xlDialogDefineName).Show "John", "=$A$1"


'--------------------------------------------------
' Hands-On 18-2
' Statements to be entered in the Immediate Window
'--------------------------------------------------

Application.FileDialog(msoFileDialogOpen).Show
Application.FileDialog(msoFileDialogSaveAs).Show
Application.FileDialog(msoFileDialogFilePicker).Show
Application.FileDialog(msoFileDialogFolderPicker).Show


'--------------------------------------------------
' Hands-On 18-3
'--------------------------------------------------

Sub ListFilters()
    Dim fdf As FileDialogFilters
    Dim fltr As FileDialogFilter
    Dim c As Integer

    Set fdf = Application.FileDialog(msoFileDialogOpen).Filters

    Workbooks.Add
    Cells(1, 1).Select
    Selection.Formula = "List of Default filters"
    With fdf
        c = .Count
        For Each fltr In fdf
            Selection.Offset(1, 0).Formula = fltr.Description & _
                ": " & fltr.Extensions
            Selection.Offset(1, 0).Select
        Next
    MsgBox c & " filters were written to a worksheet."
    End With
End Sub


Sub ListFilters2()
    Dim fdf As FileDialogFilters
    Dim fltr As FileDialogFilter
    Dim c As Integer

    Set fdf = Application.FileDialog(msoFileDialogOpen).Filters

    Workbooks.Add
    Cells(1, 1).Select
    Selection.Formula = "List of Default filters"
    With fdf
        c = .Count
        For Each fltr In fdf
            Selection.Offset(1, 0).Formula = fltr.Description & _
                ": " & fltr.Extensions
            Selection.Offset(1, 0).Select
        Next
        MsgBox c & " filters were written to a worksheet."
        .Add "Temporary Files", "*.tmp", 1
        c = .Count
        MsgBox "There are now " & c & " filters." & vbCrLf _
            & "Check for yourself."
        Application.FileDialog(msoFileDialogOpen).Show
    End With
End Sub


'--------------------------------------------------
' Hands-On 18-4
'--------------------------------------------------

Sub ListSelectedFiles()
    Dim fd As FileDialog
    Dim myFile As Variant
    Dim lbox As Object

    Application.FileDialog(msoFileDialogOpen).Filters.Clear
    Set fd = Application.FileDialog(msoFileDialogOpen)
    With fd
        .AllowMultiSelect = True
        If .Show Then
            Workbooks.Add
            Set lbox = Worksheets(1).Shapes. _
                AddFormControl(xlListBox, _
                Left:=20, Top:=60, Height:=40, Width:=300)
            lbox.ControlFormat.MultiSelect = xlNone
            For Each myFile In .SelectedItems
                lbox.ControlFormat.AddItem myFile
            Next
            Range("B4").Formula = _
                "You've selected the following " & _
                lbox.ControlFormat.ListCount & " files:"
            lbox.ControlFormat.ListIndex = 1
        End If
    End With
End Sub


Sub OpenRightAway()
    Dim fd As FileDialog
    Dim myFile As Variant

    Set fd = Application.FileDialog(msoFileDialogOpen)
    With fd
        .AllowMultiSelect = True
        If .Show Then
            For Each myFile In .SelectedItems
                .Execute
            Next
        End If
    End With
End Sub


'--------------------------------------------------
' Hands-On 18-5
' Statements to be entered in the Immediate Window
'--------------------------------------------------

Application.GetOpenFilename
Application.GetOpenFilename("excel macro-enabled files(*.xlsm), *.xlsm"),,"Highlight the File"
yourFile = Application.GetOpenFilename
?yourFile


'--------------------------------------------------
' Hands-On 18-6
' Statements to be entered in the Immediate Window
'--------------------------------------------------

yourFile = Application.GetSaveAsFilename
ActiveWorkbook.SaveAs yourFile
Workbooks("Test1.xlsx").Close
yourFile = Application.GetSaveAsFilename("Test1.xlsx", "Excel files(*.xlsx), *.xlsx",,"Name your file")



